<?php

if (@getenv("RoleRoot") !== false)
{
	$roleRoot = @getenv("RoleRoot") . '\\approot';
	$runningLocal = false;
	$CFG->wwwroot   = 'http://sitename.cloudapp.net';
}
else
{
	$roleRoot = "C:\\projects\\moodleazure\\MoodleWebRole";
	$runningLocal = true;
}

if ($roleRoot !== false)
{
    set_include_path('.;' . $roleRoot . '\\azure');
    require_once 'Microsoft/WindowsAzure/Storage/Blob.php';
    require_once 'Microsoft/WindowsAzure/Storage/Table.php';
    require_once 'Microsoft/WindowsAzure/SessionHandler.php';
    
    // Config starts here
    $azureUseLocalSQL = false; // We could also use local development database. See local db config in the next block
    $azureUseDevStorage = false; // if NOT using development storage, it is required you specify an azure account name and key properly.
    $azureAccountName = 'accountname'; // Microsoft_WindowsAzure_Credentials::DEVSTORE_ACCOUNT; // your windows azure account here so that the urls above are prefixed with 'myaccount'
    $azureAccountKey = 'base64accountkey'; // Microsoft_WindowsAzure_Credentials::DEVSTORE_KEY; // your windows azure store key here
    
	if ($azureUseDevStorage == true)
	{
		$azureAccountName = Microsoft_WindowsAzure_Credentials::DEVSTORE_ACCOUNT;
		$azureAccountKey = Microsoft_WindowsAzure_Credentials::DEVSTORE_KEY;
	}
	
    if ($azureUseLocalSQL == true)
    {
        $CFG->dbhost    = 'localhost';
        $CFG->dbname    = 'moodle19';
        $CFG->dbuser    = 'username';
        $CFG->dbpass    = 'password';
        $CFG->dbpersist =  false;
        $CFG->prefix    = 'mdl_';
    }

    // Configurable values end here. Do not modify file past this line
    
    if ($azureAccountName == Microsoft_WindowsAzure_Credentials::DEVSTORE_ACCOUNT && $azureUseDevStorage !== true)
    {
        echo "ERROR: You need to configure the azureAccountName properly in the config.azure.php file";
        exit();
    }
    
    $sqlAzureTableHost = ($azureUseDevStorage == true) ? Microsoft_WindowsAzure_Storage::URL_DEV_TABLE : Microsoft_WindowsAzure_Storage::URL_CLOUD_TABLE;
    $sqlAzureBlobHost = ($azureUseDevStorage == true) ? Microsoft_WindowsAzure_Storage::URL_DEV_BLOB : Microsoft_WindowsAzure_Storage::URL_CLOUD_BLOB;
    
    // For BLOB storage
    $storageClient = new Microsoft_WindowsAzure_Storage_Blob($sqlAzureBlobHost, $azureAccountName, $azureAccountKey);
    $storageClient->registerStreamWrapper(); // regiters azure:// on this storage client for file system storage

    // For Sessions
    $tableStorageClient = new Microsoft_WindowsAzure_Storage_Table($sqlAzureTableHost, $azureAccountName, $azureAccountKey);    
    $sessionHandler = new Microsoft_WindowsAzure_SessionHandler($tableStorageClient , 'MoodleSessions');
    $sessionHandler->register();

    $CFG->dirroot   = $roleRoot;
    $CFG->dataroot  = 'azure://moodledata';
    
    if ($azureUseDevStorage == true)
    {
        $CFG->debug = E_ALL;
        $CFG->debugdisplay = 1;
    }
}

?>